package com.atguigu.ssyx.acl.controller;

import com.atguigu.ssyx.acl.server.PermissionService;
import com.atguigu.ssyx.common.result.Result;
import com.atguigu.ssyx.model.acl.Permission;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * ClassName: Permission
 * Package: com.atguigu.ssyx.acl.controller
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-09-25
 * Time: 9:37
 */

@Api(tags = "菜单管理")
@RestController
@RequestMapping("/admin/acl/permission")
 //跨越
public class PermissionController {

    @Autowired
    private PermissionService permissionService;

    //获取权限(菜单/功能)列表
    @ApiOperation("获取权限菜单/功能列表")
    @GetMapping()
    public Result getPermission(){
        //查询出来是树型结构显示
        List<Permission> list = permissionService.queryAllPermission();
        return Result.ok(list);
    }

    //删除一个权限
    @ApiOperation("删除一个菜单")
    @DeleteMapping("/remove/{id}")
    public Result removeId(@PathVariable Long id){
        //是一个树型结构 字子节点删完 才嫩删父节点
        //递归删除
        permissionService.removeChildById(id);
        return Result.ok(null);
    }


    //保存一个权限
    @ApiOperation("添加权限")
    @PostMapping("/save")
    public Result save(@RequestBody Permission permission){
        boolean save = permissionService.save(permission);
        return Result.ok(null);
    }

    //更新一个权限
    @ApiOperation("跟新一个权限")
    @PutMapping("/update")
    public Result update(@RequestBody Permission permission){
        boolean update = permissionService.updateById(permission);
        return Result.ok(null);
    }

    //查询角色的权限
    @ApiOperation("查看某个角色权限列表")
    @GetMapping("/toAssign/{roleId}")
    public Result toAssign(@PathVariable Long roleId){


        return null;
    }

    //给角色分配权限
    @ApiOperation("给某个角色权限")
    @PostMapping("/doAssign")
    public Result doAssign(Long roleId,Long permissionId){


        return null;
    }

}
